Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(imap): avoid IMAP move loops when DeltaChat folder is aliased #4544

Merged
merged 1 commit into from Jul 14, 2023

Conversation

link2xt
Copy link
Collaborator

@link2xt link2xt commented Jul 12, 2023

Some Dovecot servers are configured
to alias "INBOX.DeltaChat" and "DeltaChat" to the same folder. In this case Delta Chat moves new emails from "INBOX" to "DeltaChat", but then discovers the same mail in "INBOX.DeltaChat" and tries to move it to "DeltaChat" again.
Each time a MOVE command is issued to move the message from "INBOX.DeltaChat" to "DeltaChat", the message gets a new UID.

To prevent such IMAP move loop between aliased folders, we do not move the message if we have already seen it on IMAP, i.e. we have its Message-ID in the imap table.
Note that we do not use rfc724_mid_exists,
because it checks the msgs table and would consider BCC-self messages seen even before we see them in the Inbox, preventing their move to the DeltaChat folder.

Duplicate messages and messages without Message-IDs are not moved anymore, but this is better
than having an infinite move loop.

@link2xt
Copy link
Collaborator Author

link2xt commented Jul 12, 2023

This is a fix for the bug that was reported on the forum: https://support.delta.chat/t/messages-received-hours-days-later/2639

@link2xt link2xt force-pushed the link2xt/prevent-imap-move-loop branch from f7b1464 to f33cf0f Compare July 12, 2023 19:17
@link2xt link2xt added the bug Something is not working label Jul 12, 2023
@link2xt link2xt force-pushed the link2xt/prevent-imap-move-loop branch from f33cf0f to b4e12e3 Compare July 12, 2023 19:50
@link2xt link2xt requested review from Hocuri and r10s July 13, 2023 20:01
@link2xt
Copy link
Collaborator Author

link2xt commented Jul 13, 2023

Would be nice to have some test, but prefetch testing is hard. Maybe something like this in Python:

  1. Send a message, observe it being moved to DeltaChat
  2. Move the message back to Inbox with direct IMAP.
  3. Send another message, observe it being moved to DeltaChat
  4. See that the first message stays in the Inbox after being moved back there.

Some Dovecot servers are configured
to alias "INBOX.DeltaChat" and "DeltaChat" to the same folder.
In this case Delta Chat moves new emails from "INBOX"
to "DeltaChat", but then discovers the same mail in "INBOX.DeltaChat"
and tries to move it to "DeltaChat" again.
Each time a MOVE command is issued to move the message
from "INBOX.DeltaChat" to "DeltaChat", the message gets a new UID.

To prevent such IMAP move loop between aliased folders,
we do not move the message if we have already seen it on IMAP,
i.e. we have its Message-ID in the `imap` table.
Note that we do not use `rfc724_mid_exists`,
because it checks the `msgs` table and would consider
BCC-self messages seen even before we see them in the Inbox,
preventing their move to the DeltaChat folder.

Duplicate messages and messages without Message-IDs
are not moved anymore, but this is better
than having an infinite move loop.
@link2xt link2xt force-pushed the link2xt/prevent-imap-move-loop branch from b4e12e3 to 9fb275b Compare July 13, 2023 21:00
@link2xt
Copy link
Collaborator Author

link2xt commented Jul 13, 2023

Added a test, checked that it fails on stable but does not on this branch.

@link2xt link2xt merged commit c14f45a into stable Jul 14, 2023
35 checks passed
@link2xt link2xt deleted the link2xt/prevent-imap-move-loop branch July 14, 2023 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is not working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants